<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div {
            position: absolute;
            top: 0;
            left: 0;
            height: 50px;
            width: 50px;
            background-color: pink;
        }
    </style>
</head>

<body>
    <div></div>
    <script>
        var div = document.querySelector('div');
        document.addEventListener('mousemove', function (e) {
            //不要忘了添加px单位
            div.style.top = e.clientY-25+'px';
            div.style.left = e.clientX-25+'px';
        })
    </script>
</body>

</html>